<template>
  <div class="aaa">
    <!-- 面包屑 -->
    <el-breadcrumb separator="/" style="font-size: 12px">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品</el-breadcrumb-item>
      <el-breadcrumb-item>商品列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card style="margin-top: 10px">
      <el-row>
        <el-col :span="6">
          <el-input
            placeholder="请输入内容"
            @input="search"
            v-model="queryInfo.query"
            class="input-with-select"
          >
            <el-button
              slot="append"
              @click="search"
              icon="el-icon-search"
            ></el-button>
          </el-input>
        </el-col>
        <el-col :span="2">
          <el-button type="primary" plain @click="jump">添加商品</el-button>
        </el-col>
      </el-row>
      <!-- 表格 -->

      <el-table
        style="margin-top: 10px; font-size: 14px"
        :data="goodsList"
        border
      >
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column
        width="450px"
          class="table_name"

          prop="goods_name"
          label="商品名称"
        >
        </el-table-column>
        <el-table-column prop="goods_price" label="商品重量" width="150px"> </el-table-column>
        <el-table-column prop="goods_number" label="商品数量" width="150px">
        </el-table-column>
        <el-table-column label="创建时间" width="350px">
          <template slot-scope="scope">
            <div>
              {{ scope.row.add_time | detaTime }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <div>
              <el-button
                type="primary"
                icon="el-icon-edit"
                circle
                plain
              ></el-button>
              <el-button
                type="danger"
                icon="el-icon-delete"
                circle
                plain
                @click="del(scope.row.goods_id)"
              ></el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      goodsList: [],
      total: 0,
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 10,
      },
      search: "",
      addDia: false,
    };
  },
  created() {
    this.getgoodsList();
  },
  methods: {
    // 渲染
    async getgoodsList() {
      const res = await this.$API.getGoodsListApi(this.queryInfo);
      console.log("商品列表", res);
      const { goods, total } = res;
      this.goodsList = goods;
      this.total = total;
    },
    // 删除
    del(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          await this.$API.getDelGoodsApi(id);
          this.getgoodsList();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 点击跳转
    jump() {
      this.$router.push("addgoods");
    },
  },
  components: {},
};
</script>

<style lang='scss'>
.aaa {
  font-size: 14px;
}
.table_name {
  font-size: 12px;
}
</style>
